package com.summer.shopping.event.checkin;

import com.summer.shopping.domain.table.Quan;
import com.summer.shopping.enums.bag.BagGoodsTypeConstant;
import com.summer.shopping.service.BagService;
import com.summer.shopping.service.QuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Component
public class CheckinEventListener {
    @Autowired
    QuanService quanService;
    @Autowired
    BagService bagService;

    private final Random random = new Random();
    @EventListener
    public void getOneQuan(CheckinEvent checkinEvent){
        Long userId = checkinEvent.get().getUserId();
        List<Quan> list = quanService.getCheckInQuan();
        int index = random.nextInt(list.size());
        Quan quan = list.get(index);
        bagService.addOneQuan(userId, BagGoodsTypeConstant.QUAN, quan.getId(), 5);
    }


}
